package com.sx.article.dao.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.sx.article.dao.IArticleDao;
import com.sx.article.entity.ArticleEntity;
import com.sx.article.entity.TitleAndArticleEntity;
import com.sx.core.BaseDao;

public class ArticleDao extends BaseDao implements IArticleDao {
	private Log log = LogFactory.getLog(this.getClass());
	
	/* (non-Javadoc)
	 * @see com.sx.article.dao.IArticleDao#approvalArticleInfo(com.sx.article.entity.ArticleEntity)
	 */
	public boolean approvalArticleInfo(ArticleEntity article) {
		boolean flag = false;
		try {
			flag = updateInfo(article, "Article.approvalArticleInfo");
		} catch (Exception e) {
			// TODO: handle exception
			log.error("审核文章信息",e);
		}
		return flag;
	}
	/* (non-Javadoc)
	 * @see com.sx.article.dao.IArticleDao#deleteInfo(com.sx.article.entity.ArticleEntity)
	 */
	public boolean deleteInfo(ArticleEntity article) {
		boolean flag = false;
		try {
			flag = super.delInfo(article, "Article.deleteArticle");
		} catch (Exception e) {
			// TODO: handle exception
			log.error("编辑文章信息",e);
		}
		return flag;
	}
	/* (non-Javadoc)
	 * @see com.sx.article.dao.IArticleDao#editInfo(com.sx.article.entity.ArticleEntity)
	 */
	public boolean editInfo(ArticleEntity article) {
		boolean flag = false;
		try {
			flag = super.updateInfo(article, "Article.editArticle");
		} catch (Exception e) {
			// TODO: handle exception
			log.error("编辑文章信息",e);
		}
		return flag;
	}
	/**
	 *查询我的文章信息 
	 **/
	public ArticleEntity findArticleById(ArticleEntity article){
		ArticleEntity arti = null;
		try {
			arti = (ArticleEntity)getSqlMapClientTemplate().queryForObject("Article.findArticleById", article);
		} catch (Exception e) {
			log.error("根据ID获取文章信息",e);
		}
		return arti;
	}
	/**
	 * 新增关联信息
	 **/
	public Integer addTitleArticleInfo(TitleAndArticleEntity aticleandtitle){
		Integer id = null;
		try {
			id = super.addInfo(aticleandtitle, "ArticleTitle.addTitleArticleInfo");
		} catch (Exception e) {
			log.error("新增文章数据信息",e);
			// TODO: handle exception
		}
		return id;
	}
	/**
	 *查询我的表单信息列表 
	 */
	public List<ArticleEntity> findArticleInfo(ArticleEntity article){
		List<ArticleEntity> list = null;
		try {
			list = super.getSqlMapClientTemplate().queryForList("Article.queryArticleInfo",article);
		} catch (Exception e) {
			log.error("查询我的表单信息列表",e);
			// TODO: handle exception
		}
		return list;
	} 
	/**
	 *查询我的表单信息数量 
	 */
	public String findArticleInfoCounts(ArticleEntity article){
		String counts = null;
		try {
			counts = (String)super.getSqlMapClientTemplate().queryForObject("Article.queryArticleInfoCount",article);
		} catch (Exception e) {
			log.error("查询我的表单信息列表的数量",e);
			// TODO: handle exception
		}
		return counts;
	} 
	/**
	 * 新增文章数据信息
	 **/
	public Integer addInfo(ArticleEntity article) {
		// TODO Auto-generated method stub
		Integer id = null;
		try {
			id = super.addInfo(article, "Article.addArticle");
		} catch (Exception e) {
			log.error("新增文章数据信息",e);
			// TODO: handle exception
		}
		return id;
	}

}
